<?php
    require_once "weixin_info.php";
    require_once "config.php";
    $invite_code = empty($_GET['invite_code']) ? '' : $_GET['invite_code'];
    if(!empty($invite_code)){
        //判定当前用户是否为业务员
        $user_sql = $mysql->query('select * from dyspw_salesman where u_id = '.$_SESSION['Member_info'][0]['id']);
        $user = $user_sql->fetch_all(MYSQLI_ASSOC);

        if(!empty($user)){
            header("Location: https://5p8.fyh5p8.com/xiaochengxu/personalCenter.php");exit;
        }
        $sale_sql = $mysql->query('select * from dyspw_salesman where invite_code = '.$invite_code);
        $sale = $sale_sql->fetch_all(MYSQLI_ASSOC);
        $mem_sql = $mysql->query('select * from dyspw_member where id = '.$_SESSION['Member_info'][0]['id']);
        $mem = $mem_sql->fetch_all(MYSQLI_ASSOC);
        if(empty($mem[0]['openid'])){
            $info = '未查询到该用户信息';
        }
        //接收邀请码，注册成为业务员状态为0
        $rand = rand(9999999,1000000);
        $invite_code = $rand . $mem[0]['id'];
        $time = time();
        //生成业务员邀请码二维码流程
        require_once "phpqrcode.php";
        define('UPLOAD_PATH', 'images/');
        define('UPLOAD_URL', '/xiaochengxu/images/qr_code/orders_hexiao/');
        //二维码流程
        $file_path =  'images/qr_code/salesman_code/';
        $qr_code_path = UPLOAD_PATH . 'qr_code/orders_hexiao/';//二维码保存的路径信息
        $sale_url = 'https://'.$_SERVER['HTTP_HOST']."/xiaochengxu/salesman_up.php?invite_code=".$invite_code;//定义二维码包含的文字信息内容
        $shop_url = 'https://'.$_SERVER['HTTP_HOST']."/xiaochengxu/shop_edit.php?invite_code=".$invite_code;//定义二维码包含的文字信息内容
        $shop_url_file = $qr_code_path . $invite_code . "shop.png";
        $sale_url_file = $qr_code_path . $invite_code . "sale.png";
        $size = 5;
        if(!\QRcode::png($sale_url, $sale_url_file, QR_ECLEVEL_M, $size)){//png方法生成二维码并保存至指定文件夹
            $invite_img = 'https://'.$_SERVER['HTTP_HOST'] . UPLOAD_URL . $invite_code . "sale.png";
        }
        if(!\QRcode::png($shop_url, $shop_url_file, QR_ECLEVEL_M, $size)){//png方法生成二维码并保存至指定文件夹
            $invite_shop = 'https://'.$_SERVER['HTTP_HOST'] . UPLOAD_URL . $invite_code . "shop.png";
        }
        $add_sale = $mysql->query("INSERT INTO dyspw_salesman (u_id, u_name, u_avatar,forbears_id,parent_id, invite_code, u_intro,invite_img,invite_shop,state,`time`) VALUES ('{$mem[0]['id']}', '{$mem[0]['username']}', '{$mem[0]['avatar']}',{$sale[0]['parent_id']},{$sale[0]['id']},$invite_code, '{$mem[0]['intro']}','$invite_img','$invite_shop',1,$time)");
        if($add_sale){
            $mysql->query("UPDATE dyspw_member SET is_vip = 4 WHERE id = ".$mem[0]['id']);
            $info = '提交成功，即将跳转个人中心!';
        }
    }
 ?>
 <!doctype html>
 <html>

 <head>
     <meta charset="utf-8">
     <meta name="viewport"
         content="height=device-height,width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
     <meta content="telephone=no" name="format-detection" />
     <link rel="stylesheet" type="text/css" href="css/salesman_up.css">
     <title>审核中</title>
 </head>
 <body>
     <div id="content" class="statusMain">
         <div class="status">
             <p class="statusImg"><img src="images/sale_state0.png" alt=""></p>
             <!-- <div class="statusImg">
                 <div class="circle-border">
                     <div class="circle-core"></div>
                 </div>
             </div> -->
             <p class="statusText"><?php echo $info; ?></p>
             <p class="promptText"><span class="promptImg"><img src="images/state_tishi.png" alt=""></span>正在跳转至用户中心<span class="time">3</span>s</p>
         </div>
     </div>
     <script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
 </body>
 <script type="text/javascript">
 $(function () {
     //演示跳转个人中心
     var i=3;
     after();
     function after(){
         $(".time").empty().append(i);
         i=i-1;
         setTimeout(function(){
             after();
         },1000);
     }
     setTimeout(function(){
         window.location.href='https://5p8.fyh5p8.com/xiaochengxu/member.php';
     },3000);//5秒后返回首页
 })
 </script>
 </html>
